package com.example.myapplication3;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListAdapter;

import java.util.ArrayList;
import java.util.List;

public class GridListActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);   //多栏列表
        setContentView(R.layout.activity_grid_list);
        GridView gridView=findViewById(R.id.mygridview);

        List<String> list1=new ArrayList<String>();
        for(int i=1;i<100;i++){
            list1.add("gitem"+i);
        }
        ListAdapter adapter=new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1,list1);
        gridView.setAdapter(adapter);
        gridView.setEmptyView(findViewById(R.id.nodata)); //当没有数据时显示nodata，同时还要注释掉list1.add("gitem"+i),这样才是没数据
    }
}